package com.eagle.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.eagle.common.entity.enums.PageSize;
import com.eagle.common.entity.po.AdminResources;
import com.eagle.common.entity.po.ParentAdminResources;
import com.eagle.common.entity.po.query.AdminResourcesQuery;
import com.eagle.common.entity.vo.PaginationResult;
import com.eagle.common.entity.vo.SimplePage;
import com.eagle.common.exception.BusinessException;
import com.eagle.common.mapper.AdminResourcesMapper;
import com.eagle.common.service.AdminResourcesService;



/**
 * 
 * 访问资源表 业务接口实现
 * 
 */
@Service("adminResourcesService")
public class AdminResourcesServiceImpl implements AdminResourcesService {

private static final Logger logger = LoggerFactory.getLogger(AdminResourcesServiceImpl.class);	@Resource
	private AdminResourcesMapper<AdminResources,AdminResourcesQuery> adminResourcesMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<AdminResources> findListByParam(AdminResourcesQuery param) {
		List<AdminResources> list = this.adminResourcesMapper.selectList(param);
		return list;
	}

	/**
	 * 根据条件查询列表
	 */
	public Integer findCountByParam(AdminResourcesQuery param) {
		Integer count = this.adminResourcesMapper.selectCount(param);
		return count;
	}

	/**
	 * 分页查询方法
	 */
	public PaginationResult<AdminResources> findListByPage(AdminResourcesQuery param) {
		int count = this.adminResourcesMapper.selectCount(param);
		int pageSize = param.getPageSize()==null?PageSize.SIZE15.getSize():param.getPageSize();
		int pageNo = 0;
		if (null != param.getPageNo()) {
			pageNo=param.getPageNo();
		}
		SimplePage page = new SimplePage(pageNo, count, pageSize);
		param.setSimplePage(page);
		List<AdminResources> list = this.adminResourcesMapper.selectList(param);
		PaginationResult<AdminResources> result = new PaginationResult<AdminResources>(page, list);
		return result;
	}

	/**
	 * 新增
	 */
	public Integer add(AdminResources bean) throws BusinessException{
		try {
			return this.adminResourcesMapper.insert(bean);
		} catch (Exception e) {
			throw new BusinessException("信息已经存在");
		}
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<AdminResources> listBean){
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.adminResourcesMapper.insertBatch(listBean);
	}

	/**
	 * 根据Code修改
	 */
	public Integer updateByCode(AdminResources bean,String code){
		return this.adminResourcesMapper.updateByCode(bean,code);
	}


	/**
	 * 根据Code删除
	 */
	public Integer deleteByCode(String code){
		return this.adminResourcesMapper.deleteByCode(code);
	}


	/**
	 * 根据Code获取对象
	 */
	public AdminResources getAdminResourcesByCode(String code){
		return this.adminResourcesMapper.selectByCode(code);
	}


	/**
	 * 根据Id修改
	 */
	public Integer updateById(AdminResources bean,Integer id){
		return this.adminResourcesMapper.updateById(bean,id);
	}


	/**
	 * 根据Id删除
	 */
	public Integer deleteById(Integer id){
		return this.adminResourcesMapper.deleteById(id);
	}


	/**
	 * 根据Id获取对象
	 */
	public AdminResources getAdminResourcesById(Integer id){
		return this.adminResourcesMapper.selectById(id);
	}

	@Override
	public List<ParentAdminResources> selectParent(AdminResourcesQuery param) {
		return this.adminResourcesMapper.selectParent(param);
	}

}